﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Pampa.CRUD.Configuration;
using Pampa.MVC.Fluent.Crud.Groups;

namespace Pampa.MVC.Fluent.Crud.Items
{
    public class EntityComboItemBuilder<TGroup, TEditor, TEntity> : EntityAbstractItemBuilder<TGroup, TEditor, TEntity, EntityComboItemBuilder<TGroup, TEditor, TEntity>>
    {
        private readonly EntityComboItem _item;

        public EntityComboItemBuilder(EntityComboItem item, string parentGroupId) : base(item, parentGroupId)
        {
            _item = item;
        }

        public EntityComboItemBuilder(GroupBuilder<TGroup, TEditor> group, EntityComboItem item) : base(group, item)
        {
            _item = item;
        }

        public EntityComboItemBuilder<TGroup, TEditor, TEntity> Description(Expression<Func<TEntity, object>> action)
        {
            _item.PropertyDescription = GetId(action);

            if (string.IsNullOrEmpty(_item.OrderBy))
                _item.OrderBy = GetId(action);

            return this;
        }

        public EntityComboItemBuilder<TGroup, TEditor, TEntity> OrderBy(Expression<Func<TEntity, object>> action)
        {
            _item.OrderBy = GetId(action);
            return this;
        }

        public EntityComboItemBuilder<TGroup, TEditor, TEntity> EmptyText(string emptyText)
        {
            _item.EmptyText = emptyText; 
            return this;
        }

        public EntityComboItemBuilder<TGroup, TEditor, TEntity> Multiple()
        {
            _item.Multiple = true;
            return this;
        }
    }
}
